package com.mapforge.gui;

import javax.swing.JList;
import javax.swing.JPopupMenu;
import javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;
import javax.swing.undo.UndoManager;

import com.mapforge.map.tools.undo.MapForgeUndoManager;

public class UndoHistoryPopup extends JPopupMenu implements UndoableEditListener{

	/**
	 * Default serial version ID, here to remove warnings
	 */
	private static final long serialVersionUID = 1L;

	UndoManager undoManager;
	JList undoManagerList;

	public UndoHistoryPopup() {
		undoManager = new MapForgeUndoManager(50);
		undoManagerList = new JList();
	}
	public UndoManager getUndoManager() {
		return undoManager;
	}

	public void setUndoManager(UndoManager manager) {
		this.undoManager = manager;
	}

	public void undoableEditHappened(UndoableEditEvent edit) {
		undoManager.addEdit(edit.getEdit());
		undoManagerList.add(new UndoRedoLabel(edit.getEdit()));
	}
}
